﻿Public Class ADDUSER
    Dim connect As CONDB = CONDB.NewConnection
    Private USERID As Integer
    Private NAME As String
    Private LASTNAME As String
    Private POSITION As String
    Private USREQ As Integer
    Private STATUS = Nothing
    Private USAPP As Integer
    Private SelectMasuser = Nothing
    Property SelectMasuser_() As String
        Get
            SelectMasuser = "SELECT masuser.`userid` as 'รหัส',masuser.`name` as 'ชื่อพนักงาน',`lastname` as 'นามสกุล',`position` as 'ตำแหน่ง',`usreq` as 'รหัสประจำตัว',`status` as 'สถานะการเปิดใช้งาน',`usapp`,masuser1.`name` as 'ผู้ทำรายการ'    "
            SelectMasuser += "FROM cpm.masuser "
            SelectMasuser += "LEFT JOIN (SELECT `userid`,`name` FROM cpm.masuser WHERE  `status` = 1) as masuser1 on masuser.`userid` = masuser1.`userid`; "
            Return SelectMasuser
        End Get
        Set(value As String)

        End Set
    End Property
    Property USERID_() As Integer
        Get
            Return USERID
        End Get
        Set(value As Integer)
            USERID = value
        End Set
    End Property
    Property USAPP_() As Integer
        Get
            Return USAPP
        End Get
        Set(value As Integer)
            USAPP = value
        End Set
    End Property
    Property NAME_() As String
        Get
            Return NAME
        End Get
        Set(value As String)
            NAME = value
        End Set
    End Property
    Property LASTNAME_() As String
        Get
            Return LASTNAME
        End Get
        Set(value As String)
            LASTNAME = value
        End Set
    End Property
    Property POSITION_() As String
        Get
            Return POSITION
        End Get
        Set(value As String)
            POSITION = value
        End Set
    End Property
    Property USREQ_() As Integer
        Get
            Return USREQ
        End Get
        Set(value As Integer)
            USREQ = value
        End Set
    End Property
    Public Sub INSERTUSER()
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Dim sql As String
        Try
            sql = "INSERT INTO cpm.masuser"
            sql += "(`name`,`lastname`,`position`,`usreq`,`usapp`) "
            sql += " VALUES ("
            sql += " '" & NAME & "' , "
            sql += " '" & LASTNAME & "' , "
            sql += " '" & POSITION & "' , "
            sql += " '" & USREQ & "' ,"
            sql += "'" & USAPP & "' ); "
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
            MsgBox("บันทึกข้อมูลเรียบร้อย", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try
    End Sub
    Public Sub UPDATEUSER()
        connect = CONDB.NewConnection()
        connect.BeginTrans()
        Dim sql As String
        Try
            sql = "UPDATE cpm.masuser SET "
            sql += " `name` = '" & NAME & "' , "
            sql += " `lastname` = '" & LASTNAME & "' , "
            sql += " `position` = '" & POSITION & "' , "
            sql += " `userq` = '" & USREQ & "',"
            sql += "`usapp` = '" & USAPP & "'"
            sql += " WHERE  `userid` ='" & USERID & "'; "
            connect.ExecuteNonQuery(sql)
            connect.CommitTrans()
            MsgBox("แก้ไขข้อมูลเรียบร้อย", MsgBoxStyle.Information)
        Catch ex As Exception
            connect.RollbackTrans()
            MsgBox(ex.ToString)
        Finally
            connect.Dispose()
        End Try

    End Sub
End Class
